package ru.urfc.portal.ui.client.googlets;

import ru.urfc.portal.ui.client.BaseGooglet;
import ru.urfc.portal.ui.client.controllers.ItemsController;
import ru.urfc.portal.ui.client.controllers.SimpleItemsController;
import ru.urfc.portal.ui.client.controllers.events.PutEvent;
import ru.urfc.portal.ui.client.descriptor.GridDescriptor;

import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Widget;

public class TheButton extends BaseGooglet {

	interface Binder extends UiBinder<Widget, TheButton> {}
	private static Binder binder = GWT.create(Binder.class);
	
	public Type<ItemsController> SAVE = new Type<ItemsController>();

	@UiHandler("save")
	void changeAccess(ClickEvent e) {
		getEventsDispatcher().fireEvent(new PutEvent(SAVE));
	}
	
	@Override
	protected void init() {
		initWidget(binder.createAndBindUi(this));
		
		GridDescriptor descriptor = new GridDescriptor(NOTIFICATION_SETTINGS, GLOBAL_NOTIFICATION_SETTINGS, NOTIFY_ALL);
		descriptor.addField("qq").setEditable();
		register(SAVE, new SimpleItemsController(descriptor) {
			@Override
			public void onUpdate(Object data) {
				MessageBox.alert("Ok", "Должники оповещены", null);
			}
		});		
	}

}